<?php
namespace app\home\widget;

use app\home\controller\Base;
use \think\View;
use think\Db;
use fast\lucn\Lucn;
/**
 * widget
 * @author  Lucn30 <Lucn30@126.com>
 */

class Block  extends Base{
    /*
	public function __construct() {
        $this->view = new \think\View();	
    }
	*/
	
	public function _initialize(){
		parent::_initialize();
			$this->assign('controller_sign',SIGN);
			$this->assign('controller_page','产品展示');
			$this->assign('method_sign',SIGN);
	}
	
	public function Aboutmore() {
	    $id = input('id/d',0);
	    $list = array();
		//$list[0]['id'] = 1;
		
		$id0 = 1;$id1 = 47;$id2 = 6;$id3 = 3;
		$i = 0;
		if($id != $id0){
		    $list[0]['id'] = $id0;
		    $list[0]['weigh'] = 10;
		    $list[0]['image'] = '/assets/home/images/gy.jpg';
		    $list[0]['link'] = url('about/show','id='.$id0);
			$i++;
		}
		
		if($id != $id1){
	    	$list[1]['id'] =  $id1;
		    $list[1]['weigh'] = 9;
		    $list[1]['image'] = '/assets/home/images/cp.jpg';
		    $list[1]['link'] = url('product/show','id='.$id1);
			$i++;
		}
		
		if($id != $id2){
		    $list[2]['id'] = $id2;
		    $list[2]['weigh'] = 8;
		    $list[2]['image'] = '/assets/home/images/jm1.jpg';
		    $list[2]['link'] = url('about/show','id='.$id2);
			$i++;
		}
		
		if($id != $id3){
		    $list[3]['id'] = $id3;
		    $list[3]['weigh'] = 7;
		    $list[3]['image'] = '/assets/home/images/lx.jpg';
		    $list[3]['link'] = url('about/show','id='.$id3);
			$i++;
		}
		
		$this->view->assign('list',$list);
        return $this->view->fetch('home/widget/aboutmore');
    }

    
    public function Contact() {
        return $this->view->fetch('led/widget/contact');
    }
	
	public function Product() {
	    //$list_category = Lucn::getCate(2,'list',false);
		$sign = 'product';//定义标识
		$map2['type'] = $sign;
		  $list_category = Db::name('Category')
		  ->where($map2)
		  ->field('id,name')
		  ->cache(true)
		  ->select();
		$this->view->assign('list_category',$list_category);
		$this->view->assign('controller_page','产品中心');
        return $this->view->fetch('led/widget/product');
    }
	
	public function Product2() {
	    $TABLE = 'product';//定义数据表名
		$map['id'] = array('NEQ',input('id/d',1));
	    $list = Db::name($TABLE)
        ->where($map)
        /*->distinct(true)*/
        ->field('id,title,image,images')
		->limit(3)
        ->select();
		//$arr_list = $list->all();
		foreach($list as $i =>$son){
			//$arr_list[$i]['thumb'] = count(json_decode($son['images'],true))>0 ? json_decode($son['images'],true)[0] :  __ROOT__.'/static/img/noimg.jpg';
			$list[$i]['thumb'] = count(json_decode($son['images'],true))>0 ? json_decode($son['images'],true)[0] :  __ROOT__.'/static/img/noimg.jpg';
		}
		$this->view->assign('controller_page', '相关产品');
		$this->view->assign('list', $list);
        return $this->view->fetch('led/widget/product2');
    }
	
	public function Photoswipe() {
        return $this->view->fetch('led/widget/photoswipe');
    }
	
	public function Photoswipejs() {
        return $this->view->fetch('led/widget/photoswipejs');
    }
}